<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<link rel="stylesheet" th:href="@{/assets/css/colorbox.css}"/>
<link rel="stylesheet" th:href="@{/assets/css/fixedColumns.dataTables.css}"/>
<link rel="stylesheet" th:href="@{/assets/css/jquery.dataTables.min.css}"/>
<head th:include="fragments/head::header"/>
<style type="text/css">
    .error {
        color: #F00
    }

    .DTFC_LeftBodyLiner {
        height: 910px ! important;
    }
</style>
<body>
<div th:include="fragments/top::top"></div>
<div class="main-container" id="main-container">
    <div class="main-container-inner">
        <div th:include="fragments/left::left" class="sidebar" id="sidebar"></div>
        <div class="main-content">
            <!--<div class="breadcrumbs" id="breadcrumbs">-->
            <!--<ul class="breadcrumb">-->
            <!--<li><i class="icon-home home-icon"></i>首页</li>-->
            <!--<li>系统管理</li>-->
            <!--<li>转案管理</li>-->
            <!--</ul>-->
            <!--</div>-->

            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <div class="row">
                            <div class="col-xs-12">
                                <h3 class="header smaller lighter blue">转案信息</h3>
                                <div class="table-header">
                                    <form class="form-inline">
                                        <shiro:hasPermission name="TRAN:ASSIGN">
                                            <input type="hidden" id="canAssign" value="true"/>
                                        </shiro:hasPermission>
                                        <shiro:hasPermission name="TRAN:CHANGE:GROUP">
                                            <input type="hidden" id="canChangeCountry" value="true"/>
                                        </shiro:hasPermission>
                                        <input type="hidden" name="transferType" id="queryType" th:value="${queryType}"/>
                                        <input type="hidden" id="currentUser" th:value="${session.user.oaid}"/>
                                        <input type="hidden" id="isChannel" th:value="${isChannel}"/>
                                        <div class="form-group">
                                            <label for="student_no">学号：</label>
                                            <input type="text" id="student_no" class="form-control input-sm"
                                                   th:value="${#httpServletRequest.getParameter('studentNo')}"
                                                   placeholder="" style="width:100px;"/>
                                        </div>
                                        <div class="form-group">
                                            <label for="sName">姓名：</label>
                                            <input type="text" id="sName" class="form-control input-sm" placeholder=""
                                                   style="width:100px;"/>
                                        </div>
                                        <div class="form-group">
                                            <label for="sName">接收人姓名：</label>
                                            <input type="text" id="receiveName" class="form-control input-sm" placeholder=""
                                                   style="width:100px;"/>
                                        </div>
                                        <!--<shiro:lacksPermission name="TRAN:CHANGE:COUNTRY">-->
                                        <div class="form-group" th:style="${queryType == 2}? 'display:none'">
                                            <label for="confirm_status">国家组：</label>
                                            <select type="" class="form-control input-sm" id="country_group"
                                                    style="width:100px;">
                                                <option th:each="countryGroup : ${countryGroups }" th:value="${countryGroup.key}" th:text="${countryGroup.value}" selected="selected"></option>
                                            </select>
                                        </div>
                                        <!--</shiro:lacksPermission>-->
                                        <shiro:lacksPermission name="TRAN:CHANGE:GROUP">
                                        <div class="form-group" th:style="'display:none'">
                                            <label for="confirm_status">用户组：</label>
                                            <select type="" class="form-control input-sm" id="user_group"
                                                    style="width:125px;">
                                                <option th:each="userGroup : ${userGroups }" th:value="${userGroup.id}" th:text="${userGroup.groupName}" selected="selected"></option>
                                            </select>
                                        </div>
                                        </shiro:lacksPermission>
                                        <shiro:hasPermission name="TRAN:ASSIGN">
                                        <div class="form-group" th:style="${queryType == 2}? 'display:none'">
                                            <label for="confirm_status">转案类型：</label>
                                            <select type="" class="form-control input-sm" id="transfer_send_type"
                                                    style="width:100px;" onchange="transferSendTypeChange()">

                                                <option value="" selected="selected">-全部-</option>
                                                <option value="1">签约即转案</option>
                                                <option value="2">分配</option>
                                                <!--<option value="3">转组</option>-->
                                            </select>
                                        </div>
                                        </shiro:hasPermission>
                                        <div class="form-group">
                                            <label for="confirm_status">确认状态：</label>
                                            <select type="" class="form-control input-sm" id="confirm_status"
                                                    style="width:100px;">
                                                <option value="" selected="selected">-全部-</option>
                                                <option class="assign" value="-1">未接受</option>
                                                <option class="assign" value="1">已接受</option>
                                                <option class="assign" value="2">已拒绝</option>
                                            </select>
                                        </div>
                                        <div class="form-group">
                                            <label for="confirm_status">结案状态：</label>
                                            <select type="" class="form-control input-sm" id="end_case_status"
                                                    style="width:100px;">
                                                <option value="0" selected="selected">未结案</option>
                                                <option value="1">已结案</option>
                                            </select>
                                        </div>
                                        <button type="button" id="query" class="btn btn-success">查询</button>
                                        <button id="empty" type="reset" class="btn btn-warning">清空</button>
                                        <shiro:hasPermission name="BATCH_TRANSFER">
                                        <button id="batch" type="button" class="btn btn-success">批量分配</button>
                                        </shiro:hasPermission>
                                    </form>
                                </div>

                                <div class="table-responsive">
                                    <div id="alert" class="alert alert-success" style="display: none;" role="alert">
                                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                            <span aria-hidden="true">&times;</span>
                                        </button>
                                        <span id="alertText"></span>
                                    </div>
                                    <table id="sample-table-2" class="table table-striped table-bordered table-hover"
                                           style="white-space: nowrap;">
                                        <thead>
                                        <tr>
                                            <th class="center">
                                                <input type="checkbox" class="checkall" onclick="checkAll(this)"/>
                                            </th>
                                            <th class="hidden-480">操作</th>
                                            <th class="hide">id</th>
                                            <th>学号</th>
                                            <th>学生姓名</th>
                                            <th>出生日期</th>
                                            <th>留学国家</th>
                                            <th>合同名称</th>
                                            <th>合同类型</th>
                                            <th>费用</th>
                                            <th>分支机构</th>
                                            <th>咨询顾问</th>
                                            <th>文签顾问</th>
                                            <th>文案员</th>
                                            <th>签证员</th>
                                            <th>院校名称</th>
                                            <th>转案顾问</th>
                                            <th>转案时间</th>
                                            <th>接收顾问</th>
                                            <th>顾问类型</th>
                                            <th>转案备注</th>
                                            <th>分配原因</th>
                                            <th>确认时间</th>
                                            <th>确认状态</th>
                                            <th>拒绝原因</th>

                                        </tr>
                                        </thead>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>

        <div th:include="fragments/bottom::bottom"></div>
    </div>

    <a href="#" id="btn-scroll-up"
       class="btn-scroll-up btn btn-sm btn-inverse"> <i
            class="icon-double-angle-up icon-only bigger-110"></i>
    </a>
</div>
<!-- /.main-container -->

<!-- Modal备注 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content"></div>
    </div>
</div>
<div th:include="fragments/js::js"></div>

<script th:src="@{/assets/js/jquery.validate.min.js}"></script>
<script th:src="@{/assets/js/jquery.validate.zh-CN.js}"></script>
<script th:src="@{/business/transferNew/list.js}"></script>
<!-- page specific plugin scripts -->
<script charset="UTF-8" th:src="@{/assets/js/1.10.15/jquery.dataTables.min.js}"></script>
<script charset="UTF-8" th:src="@{/assets/js/jquery.dataTables.bootstrap.js}"></script>
<script charset="UTF-8" th:src="@{/assets/js/dataTables.fixedColumns.js}"></script>
<script th:src="@{/assets/js/temp.js}" charset="UTF-8"></script>
<!--图片查看器-->
<script type="text/javascript">
    var queryType = $("#queryType").val();
    var currentUser = $("#currentUser").val();
    var isChannel = $("#isChannel").val();

    var canAssign = $("#canAssign").val() == 'true' ? true : false;
    var canChangeCountry = $("#canChangeCountry").val() == 'true' ? true : false;

    var invoiceIdSet = new Set([]);
    var oTable1;
    jQuery(function ($) {
        oTable1 = $('#sample-table-2').dataTable({
            "aLengthMenu": [10,20],  //用户可自选每页展示数量 5条或10条
            // "sScrollY": "450px",
            "scrollX": true,
            "scrollCollapse": true,
            "bProcessing": true,//显示搜索样式
            "bDeferRender": true,//延迟加载表格
            "fixedColumns": { //固定列的配置项
                "leftColumns": 5, //固定左边第一列
            },

            "bFilter": false,//是否使用搜索
            "bProcessing": true,
            "bDeferRender": true,//
            "sPaginationType": "bs_normal",//分页样式
            "bRetrieve": true,//是否调用后台
            "bServerSide": true,//是否以后台分页
            "sAjaxSource": "/transfer/listData",//请求路径
            "fnServerData": function (sSource, aoData, fnCallback) {
                aoData.push(
                    {"name": "userGroup", "value": $("#user_group").val()},
                    {"name": "countryGroup", "value": $("#country_group").val()},
                    {"name": "transferType", "value": $("#queryType").val()},
                    {"name": "transferSendType", "value": $("#transfer_send_type").val()},
                    {"name": "confirmStatus", "value": $("#confirm_status").val()},
                    {"name": "studentNo", "value": $("#student_no").val()},
                    {"name": "studentName", "value": $("#sName").val()},
                    {"name": "endCaseStatus", "value": $("#end_case_status").val()},
                    {"name": "receiveName", "value": $("#receiveName").val()}
                )
                $.ajax({
                    "dataType": 'json',
                    "type": "POST",
                    "url": sSource,
                    "data": aoData,
                    "success": fnCallback
                });
            },
            "aaSorting": [[0, "desc"]],
            "bSort": false,
            "aoColumns": [
                {"sClass": "center", "bSortable": false, "mData":
					function(data,row){
                        for(var i of invoiceIdSet){
                            if(i == data.id){
                                return '<input type="checkbox" onclick="check(this)" checked="checked" class="checkchild" name="checkchild" value="'+data.id+'"/> ';
                            }
                        }
                    	return '<input type="checkbox" onclick="check(this)" class="checkchild" name="checkchild" value="'+data.id+'"/> ';
					}
                },
                {"sClass": "center", "bSortable": false, "mData": function (data) {
                    var agree = '&nbsp;&nbsp;<a href="javascript:void(0);" onclick="updateStatus(' + data.sendId + ', 1)" >接受</a>&nbsp;&nbsp;';
                <!--var refuse = '&nbsp;&nbsp;<a href="javascript:void(0);" onclick="updateStatus(' + data.sendId + ', 2)" >拒绝</a>&nbsp;&nbsp;';-->
                    var refuse = '';
                    var assign = '&nbsp;&nbsp;<a href="javascript:void(0);" onclick="assign(' + data.sendId + ', \'' + data.studentNo + '\')" >分配</a>&nbsp;&nbsp;';
                    var regroup = '&nbsp;&nbsp;<a href="javascript:void(0);" onclick="regroup(' + data.sendId + ', \'' + data.studentNo + '\')" >转组</a>&nbsp;&nbsp;';
                    var changeCountry = '&nbsp;&nbsp;<a href="javascript:void(0);" onclick="changeCountry(' + data.sendId + ', \'' + data.studentNo + '\')" >转国家</a>&nbsp;&nbsp;';
                    var channelTransfer = '&nbsp;&nbsp;<a href="javascript:void(0);" onclick="changeCountry(' + data.sendId + ', \'' + data.studentNo + '\')" >转文签</a>&nbsp;&nbsp;';
                    var allot = '&nbsp;&nbsp;<a href="javascript:void(0);" onclick="allot(' + data.id + ', \'' + data.studentNo + '\')" >分配文书</a>&nbsp;&nbsp;';
                    //确认状态 1-通过 2-拒绝
                    var confirm = data.confirmStatus;
                    var receive = data.receiveNo;
                    var sendType = data.transferSendType;
                    var rt = "";
                    /*<![CDATA[*/
                    if ((confirm == null) && currentUser == receive && sendType != '1') {
                        rt += agree + refuse;
                    } else {
                        if (canAssign) {
                            rt += assign;
                            rt += allot;
                            if(canChangeCountry){
                                if(isChannel == 'true'){
                                    rt += channelTransfer;
                                }else{
                                    rt += changeCountry;
                                }
                            }
                            <!--if (queryType == '1') {-->
                            <!--rt += regroup;-->
                            <!--}-->
                        }
                    }
                    /*]]>*/

                    return rt;
                }},
                {"sClass": "center", "bVisible": false, "mData": "id"},//此列不显示
                {"sClass": "center", "bSortable": false, "mData": function (data) {
                        var studentDetail = "";
                        if(data.studentNo.indexOf('TY') == 0){
                            studentDetail = '<a class="blue" href="javascript:void(0);" onclick="toChannelStudentDetail(\'' + data.studentNo + '\')">' + data.studentNo + '</a>';
                        }else{
                            studentDetail = '<a class="blue" href="javascript:void(0);" onclick="toStudentDetail(\'' + data.studentNo + '\')">' + data.studentNo + '</a>';
                        }
                        return studentDetail;
                }},
                {"sClass": "center", "bSortable": false, "mData": "studentName"},
                {"sClass": "center", "bSortable": false, "mData": "birthday"},
                {"sClass": "center", "bSortable": false, "mData": "nationName"},
                {"sClass": "center", "bSortable": false, "mData": "contractNo"},
                {"sClass": "center", "bSortable": false, "mData": function (data) {
                    if (data.contractType == 1) return "全程";
                    if (data.contractType == 2) return "单申请";
                    if (data.contractType == 3) return "单文书";
                    if (data.contractType == 4) return "单签证";
                    return "";
                }},
                {"sClass": "center", "bSortable": false, "mData": function (data) {
                    return '<a class="blue" href="javascript:void(0);" onclick="toFee(\'' + data.studentNo + '\')">查看</a>';
                }},
                {"sClass": "center", "bSortable": false, "mData": "branchName"},
                {"sClass": "center", "bSortable": false, "mData": "salesConsultant"},
                {"sClass": "center", "bSortable": false, "mData": "copyOperator"},
                {"sClass": "center", "bSortable": false, "mData": "copy"},
                {"sClass": "center", "bSortable": false, "mData": "visaOperator"},
                {"sClass": "center", "bSortable": false, "mData": function (data) {
                    if (data.collegeName != null) {
                        return '<a class="blue" href="javascript:void(0);" onclick="toApplyDetail(\'' + data.applyId + '\')">' + data.collegeName + '</a>';
                    } else {
                        return "";
                    }
                }},
                {"sClass": "center", "bSortable": false, "mData": "operatorName"},
                {"sClass": "center", "bSortable": false, "mData": "sendTime"},
                {"sClass": "center", "bSortable": false, "mData": "receiveName"},
                {"sClass": "center", "bSortable": false, "mData": function (data) {
                    if (data.operatorType == 1) return "文签顾问";
                    if (data.operatorType == 2) return "制作文案";
                    <!--if (data.operatorType == 3) return "文书员";-->
                    <!--if (data.operatorType == 4) return "文书2";-->
                    if (data.operatorType == 5) return "规划顾问";
                    return "";
                }},
                {"sClass": "center", "bSortable": false, "mData": function (data) {
                    if(data.comment == null){
                        return "";
                    }else if (data.comment.length > 6) {
                        return '<a href="javascript:void(0);" id="'+data.id+'" onclick="toTipContent(' + data.id + ',\'' +  data.comment.replace(/\r\n/mg,'  ') + '\')" >'+data.comment.substring(0,6)+"..."+'</a>';
                    }else{
                        return data.comment;
                    }
                }},
                {"sClass": "center", "bSortable": false, "mData": function (data) {
                    if (data.transferReason == 1) return "正常分配";
                    if (data.transferReason == 2) return "休假";
                    if (data.transferReason == 3) return "工作调整";
                    if (data.transferReason == 4) return "员工离职";
                    return "";
                }},
                {"sClass": "center", "bSortable": false, "mData": "receiveTime"},
                {"sClass": "center", "bSortable": false, "mData": function (data) {
                    var result = data.confirmStatus;
                    if (result == 1) return "已通过";
                    if (result == 2) return "已拒绝";
                    return "";
                }},
                {"sClass": "center", "bSortable": false, "mData": "reason"}

            ],
            "oLanguage": {
                "sLengthMenu": "每页 _MENU_条 ",
                "sZeroRecords": "对不起，查询不到任何相关数据",
                "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录 ",
                "sInfoEmpty": "显示 0 到 0 条，共 0 条记录",
                "sInfoFiltered": "数据表中共为 _MAX_ 条记录)",
                "sProcessing": "正在加载中...",
                "sSearch": "搜索",
                "sUrl": "", //多语言配置文件，可将oLanguage的设置放在一个txt文件中，例：Javascript/datatable/dtCH.txt
                "oPaginate": {
                    "sFirst": "第一页",
                    "sPrevious": " 上一页 ",
                    "sNext": " 下一页 ",
                    "sLast": " 最后一页 "
                }
            }
            //多语言配置
        });

        //控制列隐藏
        if (queryType == 2) {
            oTable1.fnSetColumnVis(7, false, false);
            oTable1.fnSetColumnVis(8, false, false);
            oTable1.fnSetColumnVis(9, false, false);
            oTable1.fnSetColumnVis(20, false, false);
            oTable1.fnSetColumnVis(19, false, false);
        }
        if (queryType == 1) {
            oTable1.fnSetColumnVis(12, false, false);
            oTable1.fnSetColumnVis(15, false, false);
        }

        $("#query").click(function () {
            oTable1.fnDraw();
        })

    })

    $("#empty").click(function ( ) {
        $("#student_no").val("");
        location.href = '/transfer/list';
    })

    function toDetail(id) {
        location.href = '/transfer/edit?id=' + id;
    }
    /*<![CDATA[*/
    function allot(id, studentNo) {
        location.href = '/transfer/allot?id=' + id + '&studentNo=' + studentNo;
    }
    /*]]>*/

    /*<![CDATA[*/
    function assign(id, studentNo) {
        location.href = '/transfer/edit?sendId=' + id + '&studentNo=' + studentNo;
    }

    function regroup(id, studentNo) {
        location.href = '/transfer/editGroup?sendId=' + id + '&studentNo=' + studentNo + '&type=3';
    }

    function changeCountry(id, studentNo) {
        location.href = '/transfer/editGroup?sendId=' + id + '&studentNo=' + studentNo + '&type=4';
    }
    /*]]>*/

    //跳转学生详情页
    function toStudentDetail(studentNo) {
        window.open('/student/detail?studentNo=' + studentNo);
    }

    function toTipContent(id,content){
        layer.tips(content, $("#"+id), {
            tips: [1, '#3595CC'],
            time: 3000
        });
    }

    //修改状态
    function updateStatus(id, status) {
        var type = "";
        if (status == 1) {
            type = "接受";
            layer.confirm('确认接受当前转案信息？', {
                btn: ['确认', '取消'] //按钮
            }, function () {
                //加载框
                var loadIndex = layer.load(1, {shade: [0.5, '#393D49']});
                $.ajax({
                    url: "/transfer/updateReceiveStatus",
                    type: "POST",
                    data: {
                        id: id,
                        confirmStatus: status,
                    },
                    success: function (data) {
                        layer.close(loadIndex);
                        if (data) {
                            layer.confirm('操作成功！', {
                                icon: 1,
                                btn: ['确认'],
                                btn1: function (index, layero) {
                                    changeTable();
                                    parent.layer.closeAll();
                                }
                            });
                        } else {
                            layer.confirm('操作失败！', {
                                icon: 2,
                                btn: ['确认'],
                                btn1: function (index, layero) {
                                    changeTable();
                                    parent.layer.closeAll();
                                }
                            });
                        }
                    }
                });
            }, function () {
                layer.close();
            });
        } else if (status == 2) {
            type = "拒绝";
            layer.prompt({
                title: "请添加拒绝原因 <span style=" + 'color:red' + ">*</span>",
                area: ['300px', '165px'],
            }, function (value, index, elem) {
                $.ajax({
                    url: "/transfer/updateReceiveStatus",
                    type: "POST",
                    data: {
                        id: id,
                        confirmStatus: status,
                        comment: value,
                    },
                    success: function (data) {
                        if (data) {
                            layer.confirm('操作成功！', {
                                icon: 1,
                                btn: ['确认'],
                                btn1: function (index, layero) {
                                    changeTable();
                                    parent.layer.closeAll();
                                }
                            });
                        } else {
                            layer.confirm('操作失败！', {
                                icon: 2,
                                btn: ['确认'],
                                btn1: function (index, layero) {
                                    changeTable();
                                    parent.layer.closeAll();
                                }
                            });
                        }
                    }
                });
            });
        } else {
            return;
        }
    }

    function changeTable() {
        oTable1.fnDraw();
        <!--location.reload(true);-->
    }

    function toFee(studentNo) {
        window.open('http://192.168.0.2/finance/see.aspx?StudentID=' + studentNo);
    }

    //院校申请详情
    function toApplyDetail(applyId) {
        location.href = "/apply/detailPage?id=" + applyId;
    }

    function transferSendTypeChange(){
        if($("#transfer_send_type").val() == 1){
            $(".assign").hide();
        }else{
            $(".assign").show();
        }
    }

    //渠道学生详情
    function toChannelStudentDetail(studentNo) {
       window.open('/channelStudent/detail?studentNo=' + studentNo);
    }

    //全选
    function checkAll(that){
        if (that.checked) {
            $(that).attr('checked','checked')
            $('.checkchild').each(function () {
                this.checked = true;
                invoiceIdSet.add(this.value);
            });
        } else {
            $(that).removeAttr('checked')
            $('.checkchild').each(function () {
                this.checked = false;
                invoiceIdSet.delete(this.value);
            });
        }
    }
    //单选
    function check(label){
        if(label.checked){
            invoiceIdSet.add(label.value);
        }else{
            invoiceIdSet.delete(label.value);
        }
    }
</script>
<script th:src="@{/assets/js/jquery.colorbox-min.js}"></script>
<script th:src="@{/layer/layer.js}"></script>
</body>
</html>
